package cn.xi.service.checkItem;

import cn.xi.checkItem.ReportService;
import cn.xi.dao.ReportDao;
import cn.xi.pojo.Order;
import com.alibaba.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.text.SimpleDateFormat;
import java.util.*;


@Service(interfaceClass = ReportService.class)
@Transactional
public class ReportServiceImpl implements ReportService {
    @Autowired
    private ReportDao reportDao;


    @Override
    public Map getBusinessReportData() {
        Map map = new HashMap<>();
        //时间
        Date date = new Date();
        String simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd").format(date);
        map.put("reportDate", simpleDateFormat);
        //今日新增会员
        Integer integer = reportDao.selectTimeNumber(simpleDateFormat);
        map.put("todayNewMember", integer);
        //总会员数
        Integer totalMember = reportDao.totalMember();
        map.put("totalMember", totalMember);
        //本周新增会员
        Calendar calendar = Calendar.getInstance();
        int i = calendar.get(Calendar.DAY_OF_WEEK);
        if (i != 1) {
            calendar.add(Calendar.DAY_OF_MONTH, -i + 2);
        } else {
            calendar.add(Calendar.DAY_OF_MONTH, -6);
        }
        Date time = calendar.getTime();
        String format = new SimpleDateFormat("yyy-MM-dd").format(time);
        System.out.println(format);
        Integer thisWeekNewMember = reportDao.thisWeekNewMember(format, simpleDateFormat);
        map.put("thisWeekNewMember", thisWeekNewMember);

        //本月新增会员
        String format1 = new SimpleDateFormat("yyyy-MM").format(date);
        String s1 = format1 + "-01";
        String s2 = format1 + "-31";
        Integer integer1 = reportDao.thisWeekNewMember(s1, s2);
        map.put("thisMonthNewMember", integer1);

        //今日预约数
        Integer integer2 = reportDao.todayOrderNumber(simpleDateFormat);
        map.put("todayOrderNumber", integer2);

        //今日到诊数
        Integer todayVisitsNumber = reportDao.todayVisitsNumber(simpleDateFormat, Order.ORDERSTATUS_YES);
        map.put("todayVisitsNumber", todayVisitsNumber);


        calendar.add(Calendar.DAY_OF_MONTH, 6);
        Date time1 = calendar.getTime();
        String format2 = new SimpleDateFormat("yyy-MM-dd").format(time1);
        //本周预约数
        Integer thisWeekOrderNumber = reportDao.thisWeekOrderNumber(format2, simpleDateFormat);
        map.put("thisWeekOrderNumber", thisWeekOrderNumber);

        //本周到诊数
        Integer thisWeekVisitsNumber = reportDao.thisWeekVisitsNumber(format2, simpleDateFormat, Order.ORDERSTATUS_YES);
        map.put("thisWeekVisitsNumber", thisWeekVisitsNumber);

        //本月预约数
        Integer thisMonthOrderNumber = reportDao.thisWeekOrderNumber(s2, s1);
        map.put("thisMonthOrderNumber", thisMonthOrderNumber);
        //本月到诊数
        Integer thisMonthVisitsNumber = reportDao.thisWeekVisitsNumber(s2, s1, Order.ORDERSTATUS_YES);
        map.put("thisMonthVisitsNumber", thisMonthVisitsNumber);
        //套餐项
        List<Map> list = reportDao.hotSetmeal();
        map.put("hotSetmeal", list);
        return map;
    }
}
